// TimeRecordController.java
package com.kyrie.lib_sys.application.timeApplys.controller;

import com.kyrie.lib_sys.application.timeApplys.pojo.entity.TimeRecord;
import com.kyrie.lib_sys.application.timeApplys.pojo.entity.ValidationResult;
import com.kyrie.lib_sys.application.timeApplys.service.TimeRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * 用户员工时间校验类
 *
 * @author heefM
 * @date 2025-
 */

@Slf4j
@RestController
@RequestMapping("/api/time-records")
public class TimeRecordController {
    private final TimeRecordService timeRecordService;

    public TimeRecordController(TimeRecordService timeRecordService) {
        this.timeRecordService = timeRecordService;
    }

    /**
     * 新增和校验 员工的工时记录
     * @param record
     * @return
     */
    @PostMapping("/add")
    public ResponseEntity<ValidationResult> createTimeRecord(@RequestBody TimeRecord record) {
        log.info("新增员工工时记录: {}", record);
        ValidationResult result = timeRecordService.validateAndSave(record);
        return result.isValid()
                ? ResponseEntity.ok(result)
                : ResponseEntity.badRequest().body(result);
    }


    /**
     * 批量新增和校验 员工工时记录
     * @param records
     * @param employeeId
     * @return
     */
    @PostMapping("/validate-batch")
    public ResponseEntity<ValidationResult> validateRecords(
            @RequestBody List<TimeRecord> records,
            @RequestParam Long employeeId) {

        ValidationResult result = timeRecordService.validateBatchWithExisting(records, employeeId);
        return ResponseEntity.ok(result);
    }

    /**
     * 根据员工ID 获取员工工时记录
     * @param employeeId
     * @return
     */
    @GetMapping("/employee/{employeeId}")
    public ResponseEntity<List<TimeRecord>> getEmployeeRecords(@PathVariable Long employeeId) {
        log.info("根据员工id获取员工工时记录: {}", employeeId);
        List<TimeRecord> records = timeRecordService.getEmployeeRecords(employeeId);
        return ResponseEntity.ok(records);
    }




}
